package isstra.gestore;

public class GestoreMJ implements Gestore{
	private boolean release=false;
	private int cnt=0;
	private Object lock=new Object();
	public void request(){
		synchronized(lock){
			while( release ){
				try{ lock.wait(); }catch(InterruptedException e){}
			}
			cnt++;
			if( cnt==3 ) release=true;
			System.out.println(Thread.currentThread().getName()+" entra");
		}
	}//request
	public void finish(){
		synchronized(lock){
			cnt--;
			if( cnt==0 ){
				release=false;
				lock.notifyAll();
			}
			System.out.println(Thread.currentThread().getName()+" esce");
		}
	}//finish
}//GestoreMJ
